package com.crdeng.business.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.crdeng.business.entity.Consumer;
import com.crdeng.business.entity.Supplier;
import com.crdeng.business.service.ConsumerService;
import com.crdeng.business.vo.ConsumerVO;
import com.crdeng.business.vo.SupplierQueryMap;
import com.crdeng.business.vo.SupplierVO;
import com.crdeng.response.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author crdeng
 * @since 2021-02-05
 */
@Api(value = "消费方接口",tags = "消费者接口")
@RestController
@RequestMapping("/business/consumer")
public class ConsumerController {


    @Autowired
    private ConsumerService consumerService;

    @ApiOperation(value = "消费者列表",notes = "条件分页查询消费者列表")
    @PostMapping("/findConsumer")
    public Result findSupplier(@RequestParam(defaultValue = "1") Integer pageNun,
                               @RequestParam(defaultValue = "6") Integer pageSize,
                               @RequestBody SupplierQueryMap queryMap){
        IPage<Consumer> page= consumerService.findConsumer(pageNun,pageSize,queryMap);

        return Result.ok().data("list",page.getRecords()).data("total",page.getTotal());
    }

    @ApiOperation(value = "消费方列表")
    @GetMapping("/getList")
    public Result getList(){

        List<Consumer> list = consumerService.list();
        return Result.ok().data("list",list);
    }



    @ApiOperation(value = "删除消方费信息",notes = "根据ID删除消费方信息")
    @DeleteMapping("/delete")
    public Result delete(@RequestParam Long id){
        consumerService.deleteSupplierById(id);
        return Result.ok();
    }


    @ApiOperation(value = "添加供应商信息",notes = "添加供应商信息")
    @PostMapping("/add")
    public Result add(@Validated @RequestBody ConsumerVO consumerVO){
            consumerService.add(consumerVO);
        return Result.ok();
    }


    @ApiOperation(value = "编辑供应商信息",notes = "编辑供应商信息")
    @PostMapping("/edit")
    public Result edit(@Validated @RequestBody ConsumerVO consumerVO){
            consumerService.edit(consumerVO);
        return Result.ok();
    }


}

